package com.sanyang.pda.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.sanyang.pda.bean.ScanBean;
import com.sanyang.pda.view.ScanButView;
import com.wangshen.base.dialog.base.BaseDialog;
import com.wangshen.base.util.ToastUtils;
import com.wangshen.projectbase.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChooseDetermineDialog extends BaseDialog {
    @BindView(R.id.tv_choose_determine)
    TextView tvChooseDetermine;
    @BindView(R.id.iv_close)
    ImageView ivClose;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.iv_scan)
    ScanButView ivScan;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    private OnChooseClick onChooseClick;
    public ChooseDetermineDialog(@NonNull Context context,OnChooseClick onChooseClick) {
        super(context);
        this.onChooseClick=onChooseClick;
    }

    @Override
    public void initView() {
        setCancelable(true);
        ButterKnife.bind(this);
        ivScan.setScanCallBack(new ScanButView.ScanCallBack() {
            @Override
            public void callBack(ScanBean scanBean) {
                if (scanBean .getType() ==2){
                    tvName.setText(scanBean.getCode());
                }
            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public int getView() {
        return R.layout.dialog_choose_determine;
    }

    @OnClick(R.id.iv_close)
    public void onIvCloseClicked() {
        dismiss();
    }

    @OnClick(R.id.tv_cancel)
    public void onTvCancelClicked() {
        dismiss();
    }

    @OnClick(R.id.tv_confirm)
    public void onTvConfirmClicked() {
        if (TextUtils.isEmpty(tvChooseDetermine.getText())){
            ToastUtils.showToast(getContext(),getContext().getString(R.string.picking_location)+getContext().getString(R.string.not_be_empty));
            return;
        }
        if (onChooseClick != null){
            onChooseClick.onScanResult(tvName.getText().toString());
        }
        dismiss();
    }
    public interface OnChooseClick{
        void onScanResult(String result);
    }
}
